/*
 * ChooseAddressManagerHolder.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.viewholder;

import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.UserAddress;
import com.yidiandao.business.ui.widget.listview.ViewHolder;

/** 选择地址ViewHolder */
public class ChooseAddressManagerHolder extends ViewHolder {

    public CheckBox mCbChoose;
    public TextView mTvDelete;
    public TextView mTvEdit;
    public LinearLayout mLlytSetDefault;
    private TextView mTvName;
    private TextView mTvNumber;
    private TextView mTvAddress;

    @Override
    protected void initView(View rootView) {
        mTvName = (TextView) rootView.findViewById(R.id.tv_name);
        mTvNumber = (TextView) rootView.findViewById(R.id.tv_number);
        mCbChoose = (CheckBox) rootView.findViewById(R.id.cb_choose);
        mTvDelete = (TextView) rootView.findViewById(R.id.tv_delete);
        mTvEdit = (TextView) rootView.findViewById(R.id.tv_edit);
        mTvAddress = (TextView) rootView.findViewById(R.id.tv_address);
        mLlytSetDefault = (LinearLayout) rootView.findViewById(R.id.llyt_set_default);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_choose_address_manager;
    }

    public void refreshUI(UserAddress userAddress) {
        String address =
                userAddress.getProvince()
                        + userAddress.getCity()
                        + userAddress.getDistrict()
                        + userAddress.getAddress();

        mTvName.setText(userAddress.getConsignee());
        mTvNumber.setText(userAddress.getTel());
        mTvAddress.setText(address);
        mCbChoose.setChecked(userAddress.isDefault());
    }

    /** 当前地址是否是默认地址 */
    public boolean isDefaultAddress() {
        return mCbChoose.isChecked();
    }
}
